/*
 * TITLE:Bug
 * AUTHOR:Manori Thakur
 * PURPOSE: Describes the properties of Bug
 */
package com.example.android.debuggermenu.models;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import com.example.android.debuggermenu.models.components.*;

public class Bug {

    private Bitmap bitmap;  //actual Bitmap
    private int x;          //X co-ordinate
    private int y;          //Y co-ordinate
    private boolean bugTouched;  //maintains the state of the bug
    private Speed speed;	// the speed with its directions
    private double col_width,col_height,col_xoffset,col_yoffset;


    public Bug(Bitmap bitmap, int x, int y) {
        this.bitmap = bitmap;
        this.x = x;
        this.y = y;
        this.col_width = this.bitmap.getWidth()*0.80;
        this.col_height = this.bitmap.getHeight()*0.80;
        this.col_xoffset = (this.bitmap.getWidth() - this.col_width) / 2;
        this.col_yoffset = (this.bitmap.getHeight() - this.col_height) / 2;
        this.speed = new Speed();
    }

    public Bitmap getBitmap() {
        return this.bitmap;
    }

    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    public int getX() {
        return this.x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return this.y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public double getCol_Width() {
        return this.col_width;
    }
    public double getCol_Height() {
        return this.col_height;
    }
    public double getCol_XOffset() {
        return (int)this.col_xoffset;
    }
    public double getCol_YOffset() {
        return this.col_yoffset;
    }

    public Speed getSpeed() {
	return speed;
    }

    public void setSpeed(Speed speed) {
	this.speed = speed;
    }

    public boolean isBugTouched() {
        return bugTouched;
    }

    public void setBugTouched(boolean bugTouched) {
        this.bugTouched = bugTouched;
    }

    public void draw(Canvas canvas) {
        canvas.drawBitmap(bitmap, x, y, null);
        //canvas.drawBitmap(bitmap, x - (bitmap.getWidth() / 2), y - (bitmap.getHeight() / 2), null);
    }

    /**
     * Method which updates the droid's internal state every tick
     */
    public void update() {
	if (!bugTouched) {
		x += (speed.getXv() * speed.getxDirection());
		y += (speed.getYv() * speed.getyDirection());
	}
    }

    public void handleActionDown(int eventX, int eventY) {
        if (eventX >= (x - bitmap.getWidth() / 2) && (eventX <= (x + bitmap.getWidth()/2))) {
            if (eventY >= (y - bitmap.getHeight() / 2) && (y <= (y + bitmap.getHeight() / 2))) {
                //bug is touched
                setBugTouched(true);
            } else {
                setBugTouched(false);
            }
        } else {
            setBugTouched(false);
        }
    }

    public RectF getRect() {
        return new RectF(x,y,x+bitmap.getWidth(),y+bitmap.getHeight());
        //return new Rect(x-bitmap.getWidth()/2,y-bitmap.getHeight()/2,x+bitmap.getWidth()/2,y+bitmap.getHeight()/2);
    }
    
    public float getRadius() {
        return bitmap.getWidth()/2;
    }
    
    public float getCenterX() {
        return x+bitmap.getWidth()/2;
    }
    
    public float getCenterY() {
        return y+bitmap.getHeight()/2;
    }
    
    
}
